package lru.review5_21;

import java.util.HashMap;

public class TwoSum1 {

    public int[] twoSum(int[] nums, int target) {
        HashMap<Integer,Integer> map = new HashMap<>();
        for (int i = 0; i <nums.length ; i++) {
 //  CKG TODO 2023/5/21: 巧妙地使用ｍａｐ集合　
            if (map.containsKey(target-nums[i])){
                return new int[]{i,map.get(target-nums[i])};
            }
         map.put(nums[i],i );
        }
        return  new int[]{-1,-1};
    }

    public static void main(String[] args) {
        int[] ints = {1, 2, 3, 4, 5};
        TwoSum1 twoSum1 = new TwoSum1();
        int[] ints1 = twoSum1.twoSum(ints, 4);
        for (int i = 0; i < ints1.length; i++) {
            System.out.println(ints1[i]);
        }
    }




}
